package cn.itcast.algorithm.ch1;

public class FactorialTest {
    public static void main(String[] args) {
        //测试，计算10的阶乘
        long result = fun1(10);
//        long result = fun2(10);
        System.out.println(result);
    }

    //计算n的阶乘 递归 每次方法调用都会占用栈内存
    public static long fun1(long n) {
        if (n == 1) {
            return 1;
        }
        return n * fun1(n - 1);
    }

    //计算n的阶乘
    public static long fun2(long n){
        int result=1;
        for (long i = 1; i <= n; i++) {
            result*=i;
        }
        return result;
    }
}
